console.log('导入是否正确：', axios, '=====', Qs);

//#region qs的测试部分
let div1 = document.getElementById('div1');

let json = {
  id: 100,
  info: '张三',
};

// qs的功能就是转化json为查询字符串(get提交数据的格式)
div1.innerHTML = Qs.stringify(json);

let query = 'id=100&info=%E5%BC%A0%E4%B8%89';
console.log('还原查询字符串为json:', Qs.parse(query));

query =
  'q=黑暗骑士&form=ANNTH1&refig=6657f2ee66ae4a21b000a8c62e346775&pc=LCTS&adppc=EdgeStart';
console.log('还原查询字符串为json:', Qs.parse(query));

//#endregion

//#region ajax请求功能演示

let txtecho = document.getElementById('txtecho');
let btnecho = document.getElementById('btnecho');
let divecho = document.getElementById('divecho');

const BASE_URL = 'https://api.huhuiyu.top';

btnecho.addEventListener('click', () => {
  let promise = axios({
    url: BASE_URL + '/test/echo?echo=' + txtecho.value,
    data: '',
    method: 'get',
  });

  promise
    .then((resp) => {
      // divecho.innerHTML = JSON.stringify(resp.data);
      divecho.innerHTML = resp.data.data;
    })
    .catch((err) => {
      console.error('应用程序异常：', err);
    });
});

//#endregion

//#region 足球俱乐部查询演示

let btnFootball = document.getElementById('btnFootball');
let divFootball = document.getElementById('divFootball');

btnFootball.addEventListener('click', () => {
  // json格式的参数
  let params = {
    orderBy: 1,
    pageNumber: 1,
    pageSize: 5,
  };
  // 转换参数为查询字符串格式
  let data = Qs.stringify(params);
  console.log('传递的数据：', data);
  // 发起请求
  let promise = axios({
    url: BASE_URL + '/crud/footballteam?' + data,
    data: '',
    method: 'get',
  });

  promise
    .then((resp) => {
      divFootball.innerHTML = JSON.stringify(resp.data,null,2);
    })
    .catch((err) => {
      console.error(err);
    });
});

//#endregion
